/*
 * @filename RestTemplateCustomizer.java
 * @author barry
 * @version 0.0.1
 * @date 2020年3月31日
 */
package com.bnzj.cloud.gateway.config;

import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * 配置RestTemplate的超时设置,REACTIVE模式无效
 * @author barry
 * @date 2020-03-31
 * @see org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration
 */
@Component
public class CustomizeRestTemplateCustomizer implements RestTemplateCustomizer {

    @Override
    public void customize(RestTemplate restTemplate) {
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setConnectTimeout(10000);
        requestFactory.setReadTimeout(10000);
        restTemplate.setRequestFactory(requestFactory);
    }

}
